package buco.jsonrpc;

import java.io.IOException;
import java.io.Writer;
import java.util.List;

import org.json.simple.*;

import buco.core.api.*;

public class SemanticMessageConverter implements JSONStreamAware {
	private List<SemanticMessage> warnings; 
	
	public SemanticMessageConverter(List<SemanticMessage> warnings) {
		this.warnings = warnings; 
	} 
	
	@SuppressWarnings("unchecked")
	@Override
	public void writeJSONString(Writer wr) throws IOException {
		JSONArray result = new JSONArray();
		for(SemanticMessage warning : warnings) { 
			JSONObject jsonWarning = new JSONObject(); 			
			jsonWarning.put("bundleID", warning.getBundle().getBundleID());			
			jsonWarning.put("message", warning.getMessage());
			jsonWarning.put("type", warning.getType().toString());
			result.add(jsonWarning); 
		}		
		result.writeJSONString(wr);
	}

}
